package com.bw.shopping.mvvm.viewmodel;

import android.content.Context;
import android.content.SharedPreferences;

import androidx.databinding.ObservableField;

import com.alibaba.android.arouter.launcher.ARouter;
import com.bw.mvvm_comom.BaseApplication;
import com.bw.mvvm_comom.entity.BaseEntity;
import com.bw.mvvm_comom.mvvm.BaseViewModel;
import com.bw.shopping.mvvm.adapter.CarAdapter;
import com.bw.shopping.mvvm.model.CarModel;
import com.bw.shopping.mvvm.model.entity.CarListEntity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.jar.Manifest;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class CarViewModel extends BaseViewModel<CarModel> {
    public CarAdapter adapter = new CarAdapter();
    public ObservableField<String>allPrice = new ObservableField<>("合计:¥0");
    public ObservableField<Boolean>allCheck = new ObservableField<>(false);
    public ObservableField<String> edtStr = new ObservableField<>("编辑");
    @Override
    public void onCreate() {
        super.onCreate();
//        int id = ((UserProvider) ARouter.getInstance().build("/usergroup/userprovider").navigation()).getUserId();
        SharedPreferences sj = BaseApplication.getApplication().getSharedPreferences("sj", Context.MODE_PRIVATE);
        int id = sj.getInt("id", 1);
        HashMap<String,Object> map = new HashMap<>();
        map.put("id",id);
        m.requsetCarModel(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(this);
    }

    public void edtClickListener(){
//        List<CarListEntity.Values> list = new ArrayList<>();
//        if (list.size() == 0)
//            return;
//        List<CarListEntity.Values> datas = new ArrayList<>();
//        for (CarListEntity.Values values: list) {
//            values.edtFlag = !values.edtFlag;
//            datas.add(values);
//        }
//        if (datas.get(0).edtFlag){
//            edtStr.set("完成");
//        }else {
//            edtStr.set("编辑");
//        }
//        adapter.setNewInstance(datas);

    }

    public void orderListener(){

    }

    public void checkAllListener(){

    }

    @Override
    protected void result(BaseEntity baseEntity) {
        if (baseEntity instanceof CarListEntity){
            CarListEntity carListEntity = (CarListEntity) baseEntity;
            adapter.setNewInstance(carListEntity.data);
        }
    }
}
